﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///SuperType 的摘要说明
/// </summary>
public partial class SuperType
{
    DataTableDataContext db=new DataTableDataContext();
    SubType subTypeName = new SubType();

    //根据ID查找大类型名
    public IEnumerable<SuperType> GetSuperTypeNameById(int id)
    {
        var superTypes = from s in db.SuperType where s.superTypeId == id select s;
        return superTypes;
    }



   //增加大类型信息
    public void InsertSuperType(string name)
    {
        SuperType types = new SuperType {superTypeName=name};
        db.SuperType.InsertOnSubmit(types);
        db.SubmitChanges();
    }

    //增加大类型并返回ID
    public int InsertSuperTypeReturnId(string name)
    {
        SuperType types = new SuperType { superTypeName = name };
        db.SuperType.InsertOnSubmit(types);
        db.SubmitChanges();
        int id = types.superTypeId;
        return id;
    }

    //删除大类型信息
    public void DeleteSuperType(int id)
    {
        var superTypes = from s in db.SuperType where s.superTypeId == id select s;
        var subTypes = from sub in db.SubType from s in db.SuperType where sub.superTypeId == s.superTypeId && s.superTypeId==id select sub;
        foreach (var subType in subTypes)
        {
            subTypeName.DeleteSubType(subType.subTypeId);
        }
        foreach (var superType in superTypes)
        {
            db.SuperType.DeleteOnSubmit(superType);
            db.SubmitChanges();
        }
 
    }
	
}